package cn.wolfcode.wolf2w.destination.factory;


import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.destination.RemoteDestinationService;
import cn.wolfcode.wolf2w.destination.entity.TaDestination;
import org.apache.commons.compress.utils.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 旅游日记 远程服务降级回调
 *
 * @author libai
 * @date 2024-08-02
 */
@Component
public class RemoteDestinationFallbackFactory implements FallbackFactory<RemoteDestinationService> {


    @Override
    public RemoteDestinationService create(Throwable throwable) {
        return new RemoteDestinationService() {
            @Override
            public R<TaDestination> getById(Long id) {
                TaDestination destination = new TaDestination();
                destination.setId(-1l);
                destination.setName("目的地错误");
                return R.fail(destination);
            }

            @Override
            public R<List<TaDestination>> list(String source) {
                return R.fail(Lists.newArrayList(), "查询目的地列表信息失败:" + throwable.getMessage());
            }
        };
    }
}
